<template>
<!-- 参考链接 https://juejin.cn/post/6844904067873931272-->
  <div>
    <el-dialog title="表单嵌套表格" :visible.sync="dialogTableVisible">
      <el-form :model="Obj" ref="form" size="small">
         <el-table :data="Obj.tableData">
           <el-table-column property="date" label="日期" width="150"></el-table-column>
           <el-table-column property="name" label="姓名" width="200"></el-table-column>
           <el-table-column property="address" label="地址"></el-table-column>
           <el-table-column property="radio1" label="反馈">
             <template slot-scope="scope">
               <el-form-item :prop="'tableData.' + scope.$index + '.' + 'radio1'" :rules="rules['radio1']">
                 <el-radio-group v-model="scope.row.radio1">
                   <el-radio label="冲突"></el-radio>
                   <el-radio label="不冲突"></el-radio>
                 </el-radio-group>
               </el-form-item>
             </template>
           </el-table-column>
           <el-table-column property="textArea" label="意见">
             <template slot-scope="scope">
               <el-form-item :prop="'tableData.' + scope.$index + '.' + 'textarea'" :rules="rules['textarea']">
                 <el-input
                   type="textarea"
                   :rows="5"
                   placeholder="请输入内容"
                   maxlength='30'
                   show-word-limit
                   v-model="scope.row.textarea">
                 </el-input>
               </el-form-item>
             </template>
           </el-table-column>
         </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
         <el-button @click="dialogTableVisible = false">取 消</el-button>
         <el-button type="primary" @click="handleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'FormTable',
  data () {
    return {
      dialogTableVisible: false,
      Obj: {
        tableData: [
          {
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄',
            radio1: '',
            textarea: ''
          },
          {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄',
            radio1: '',
            textArea: ''
          }
        ]
      },
      rules: {
        radio1: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        textarea: [
          { required: true, message: '请填写意见', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init () {
      this.dialogTableVisible = true
    },
    handleConfirm () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          console.log(this.Obj.tableData)
          this.Obj.tableData.forEach((item, index, arr) => {
            console.log(arr[index].radio1)
          })
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
